package com.lz.demo4;

import java.util.Random;
import java.util.Scanner;

/**
 * @ClassName TestPet
 * @Description 测试
 * @Author 2214361854
 * @Date 2022/5/28 14:38
 * @Version 1.0
 */
public class TestPet {
    public static void main(String[] args) {
        System.out.println("1. 狗\n" +
                "2. 猫\n" +
                "选择：> ");
        int c = new Scanner(System.in).nextInt();
        System.out.print("给宠物起个名字：");
        String n = new Scanner(System.in).nextLine();
        if (c == 1) {
            //定义猫狗变量
            Pet dog  = new Dog(n);
            play(dog);
        } else {
            Pet cat = new Cat(n);
            play(cat);
        }
    }

    private static void play(Pet pet) {
        System.out.println("按回车执行");
        while (true) {
            new Scanner(System.in).nextLine();
            int r = new Random().nextInt(6);
            switch (r) {
                case 0:
                    pet.feed();
                    break;
                case 1:
                    pet.play();
                    break;
                default:
                    pet.punish();
                    break;
            }
        }
    }
}

